package org.dream.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang.StringUtils;

/**
 * @author qiuriyuchen E-mail:panpan_001@126.com 日期工具类
 */
public class DateUtil {
	/**
	 * 得到当前日期精确到天的字符串，格式为yyyy-MM-dd
	 * 
	 * @return当前日期的字符串
	 */
	public static String getCurrDay() {

		return new SimpleDateFormat("yyyy/MM/dd").format(new Date());
	}
	public static String getMonthPreDay(int month) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		calendar.add(Calendar.MONTH, month);
		return new SimpleDateFormat("yyyy/MM/dd").format(calendar.getTime());
	}

	/**
	 * 
	 * 根据字符串得到日期
	 */
	public static Date getDate(String str) {
		if (StringUtils.isEmpty(str)) {
			return null;
		}
		SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
		Date date = null;
		try {
			date = df.parse(str);

		} catch (ParseException e) {

			e.printStackTrace();
		}
		return date;
	}

	public static boolean isWeekDay(String str) {
		Date date = getDate(str);
		return isWeekDay(date);
	}

	public static boolean isWeekDay(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
		if (week == 0 || week == 6) {
			return true;
		} else {
			return false;
		}

	}

	/**
	 * 得到当前日期精确到天的字符串，格式为yyyy-MM-dd
	 * 
	 * @return当前日期的字符串
	 */
	public static String getDateStr(Date date) {
		return new SimpleDateFormat("yyyy/MM/dd").format(date);
	}
}
